Start typing to search every page on this site.

Use ↑ and ↓ to move through results, then Enter to open one.

    Skip to main content

    15. Introduction to coding theory#

    Data sent over a radio link, through a cable, or stored on a disk is subject to physical noise, and some of the bits that arrive differ from the bits that were sent. Suppose, for example, that a device sends bits and that each bit is flipped with probability , independently of the other bits. The whole sequence arrives without a single flipped bit with probability which is less than one chance in twenty thousand.

    The sender cannot prevent the noise, but it can add extra bits, computed from the message, that allow the receiver to notice errors or to repair them. Coding theory is the study of such schemes. Extra bits make transmission more reliable and also make it slower, and the subject asks how much reliability can be obtained for a given number of extra bits.

    In this note we define codes, channels, and decoders, and we use binomial coefficients to compute how many errors a block of bits contains. The computation shows that a code that protects only short blocks cannot make long messages reliable, and it tells us how many errors a code on long blocks has to correct.

    After studying these notes, you will be able to do the following.

    • Describe a code by its encoding map, code words, block length, rate, and decoder, and describe a channel by the probabilities of its outputs.

    • Compute the probability of a given error pattern, and of exactly errors, on a binary symmetric channel.

    • Compute the probability that uncoded transmission, a parity check, or triple repetition fails.

    • Explain why a code working on short blocks fails on long messages, and bound the probability of many errors in a long block.

    15.1 Errors and redundancy#

    An error is a position in which the received symbol differs from the transmitted symbol. A receiver can deal with errors in two ways.

    • In error detection, the receiver only decides whether an error occurred. If it finds one, it asks the sender to transmit the data again. This is how computer networks usually operate, because a second transmission is cheap.

    • In error correction, the receiver reconstructs the data without a second transmission. This is necessary when no second transmission is possible, for instance for a signal from a space probe, for a broadcast, or for data read from an old storage device.

    Both require redundancy: bits that are sent in addition to the message and are computed from it. The following two examples are the simplest codes for detection and for correction, and we will return to them throughout the unit.

    Example 15.1 (A parity bit)#

    A sender wants to transmit four bits . It appends a fifth bit, called the parity bit, chosen so that the five transmitted bits contain an even number of s. For the message 1101, which contains three s, the parity bit is , and the sender transmits 11011.

    Flipping one bit changes the number of s by exactly one, so it turns an even number of s into an odd number. For instance, if the third bit of 11011 flips, the receiver gets 11111, which contains five s. Since every transmitted block contains an even number of s, the receiver concludes that an error occurred. Thus every single error is detected.

    The parity bit has two limitations.

    • It does not locate the error. The word 11111 arises from 11011 by flipping the third bit, but also from 11110 (the encoding of 1111) by flipping the fifth bit, and from 01111 (the encoding of 0111) by flipping the first bit.

    • It does not detect two errors. If the first and fourth bits of 11011 flip, the receiver gets 01001. This word contains two s and is the encoding of 0100, so the receiver accepts a wrong message.

    Example 15.2 (Triple repetition)#

    The sender transmits each bit three times: as 000 and as 111. The receiver decodes each block of three bits by majority vote, so 010 is decoded as and 110 as . If at most one of the three bits flips, the majority of the block is still the bit that was sent, so every single error within a block is corrected. In exchange, the sender transmits three bits for every bit of the message.

    15.2 Codes, channels, and decoders#

    We describe a transmission as three steps: The sender and the receiver agree in advance on the encoding and the decoding. The channel is the physical medium; it is random, and neither party controls it. We now make each of the three steps precise.

    15.2.1 Binary words#

    We write with addition modulo , so that Adding to a bit leaves it unchanged, and adding flips it. A binary word of length is a sequence of elements of , and denotes the set of all such words. By the product rule, . We write words as strings such as 10110, and for the th bit of a word .

    Words of the same length are added bit by bit: The sum has a exactly in the positions where and differ. In particular , where is the word consisting of zeros, and therefore holds exactly when .

    15.2.2 Codes and channels#

    Definition 15.3 (Code, block length, rate)#

    An encoding of -bit messages is an injective map . Its image is the code, the elements of are the code words, and is the block length. The rate of the code is

    The encoding is required to be injective so that two different messages are never sent as the same code word; otherwise the receiver could not tell them apart even when no error occurs. The rate is the fraction of the transmitted bits that carry the message; the remaining fraction is redundancy. Uncoded transmission has rate , triple repetition has rate , and the parity bit of Example 15.1 gives rate .

    A channel takes a transmitted word and produces a received word, and the received word is random. We describe a channel by listing, for each word that may be sent, the probability of each word that may be received.

    Definition 15.4 (Channel)#

    A channel on words of length is a probabilistic function that assigns to every input word a random word . The function is random in the sense that transmitting two times can yield different results. To make this mathematically precise, the function is actually , where is the space of "events" that control the realization of possible errors introduced by the channel.

    Definition 15.5 (Decoder)#

    A decoder for an encoding is a map that assigns to every word either a message in or the output “failure”, such that for every message .

    The condition says that the decoder returns the correct message whenever no error occurs. The output “failure” lets a decoder report a detected error instead of guessing. A decoder must be defined on all of , not only on the code words, because the channel can turn a code word into any word.

    Example 15.6 (Triple repetition as a code)#

    Consider messages of bits. The sender repeats each bit three times: The block length is , the code is and the rate is .

    The receiver cuts a received word into the two blocks and and decodes each block by majority, using the following table for a block of three bits.

    block000001010100011101110111
    majority bit

    The decoder returns the two majority bits as the message. For example, , because the block 110 has majority and the block 010 has majority . Since each block of a code word is 000 or 111, we have , so is a decoder in the sense of Definition 15.5. Each block has four values with majority and four with majority , so each of the four messages is returned for of the words of length .

    Suppose the message 10 is sent as .

    • If the second and fifth bits flip, the receiver gets 101010. The blocks 101 and 010 have majorities and , and the decoder returns the correct message 10. Two errors are corrected here because they lie in different blocks.

    • If the first and second bits flip, the receiver gets 001000. Both blocks have majority , and the decoder returns the wrong message 00.

    Thus the decoder returns the correct message exactly when neither block contains two or more errors. It corrects every single error, and it corrects a pair of errors exactly when the two errors lie in different blocks; this happens for of the pairs of positions.

    Example 15.7 (The parity check as a code)#

    For messages of bits, the encoding appends the bit , computed in . The code consists of the words of length with an even number of s. Exactly half of the words of length have this property, so and . The decoder returns the first bits when the received word contains an even number of s, and returns failure when it contains an odd number.

    15.3 The binary symmetric channel#

    The simplest model of a noisy channel treats every bit in the same way and treats different bits independently.

    Definition 15.8 (Binary symmetric channel)#

    Let and . The binary symmetric channel transmits words of length , one bit at a time. Each bit is flipped with probability and arrives unchanged with probability , and what happens to one bit is independent of what happens to the other bits.

    Two bits on the left labeled 0 and 1 (bit sent) and two on the right labeled 0 and 1 (bit received). Horizontal arrows from 0 to 0 and from 1 to 1 are labeled 1 minus p. Crossing arrows from 0 to 1 and from 1 to 0 are labeled p.
    Figure 15.1: The binary symmetric channel for a single bit. A bit is received unchanged with probability and flipped with probability .#

    Figure 15.1 shows the channel for a single bit. The word “symmetric” refers to the fact that a becomes a with the same probability as a becomes a . We assume . If , the receiver can flip every received bit and obtain a binary symmetric channel with flip probability . If , every received bit is or with probability regardless of what was sent, and the received word carries no information.

    Definition 15.9 (Error pattern, Hamming weight)#

    If is sent and is received, the error pattern is the word . The Hamming weight of a word is the number of positions with .

    The error pattern has a exactly in the positions where the channel flipped a bit, so , and is the number of errors. For example, if 11011 is sent and 11111 is received, the error pattern is , which has weight . The next proposition computes, for , the probability that a word is received when a word is sent.

    Proposition 15.10 (Probabilities on the binary symmetric channel)#

    Let words of length be sent over .

    1. A given error pattern with occurs with probability . Equivalently, if and differ in exactly positions, then the probability that is received when is sent is .

    2. The probability that exactly errors occur is

    Proof#

    The error pattern occurs when the channel flips each of the positions where has a and keeps each of the other positions. These events are independent, so the probability that all of them happen is the product of factors and factors . The word is received from exactly when the error pattern is , which has weight when and differ in positions.

    An error pattern of weight is determined by the set of positions that hold its s, so there are such patterns. Different patterns are different outcomes, so the probability of exactly errors is the sum of their probabilities, which is .

    By the binomial theorem, , as it must be, since every outcome has some number of errors. The numbers form the binomial distribution with parameters and .

    Proposition 15.11 (Expected number of errors)#

    The expected number of errors in a block of length sent over is

    Proof#

    The term with is zero. For we use the identity : both sides count the ways to choose of the positions and mark one of the chosen positions, the left side choosing the set first and the right side choosing the marked position first. Hence With , the last sum is by the binomial theorem.

    For , a block of bits contains on average errors, and a block of bits contains on average errors.

    15.4 Short blocks and long messages#

    Example 15.12 (One bit with flip probability )#

    Without coding, a bit is received incorrectly with probability . With triple repetition, majority vote is wrong when at least two of the three bits flip. By Proposition 15.10 with , this has probability Repetition lowers the probability of a wrong bit from to about , and it lowers the rate from to .

    A message of bits is correct only if every one of its bits is correct. Without coding, each bit is correct with probability , independently, so the message is correct with probability . With triple repetition the message is sent as blocks of three bits, each block is decoded correctly with probability , and the blocks are independent, so the message is correct with probability . For these probabilities are as follows.

    message length no coding, triple repetition,

    For a thousand bits, repetition raises the probability of a correct message from almost to about . For a million bits, however, repetition does not help in practice: the million blocks contain on average blocks with two or more errors, and the message is correct only if there are none.

    The same failure occurs for every code that works on blocks of a fixed length . If each block is decoded incorrectly with some probability , a message of bits consists of independent blocks and is correct with probability where we used the inequality . The right side tends to as grows. To send long messages reliably, we must therefore use long blocks, and the number of errors a code corrects in a block must grow with the block length. To find how fast it must grow, we study how many errors a block of length contains.

    15.5 The number of errors in a long block#

    Figure 15.2 shows the probabilities for and two block lengths. For , the most likely outcome is a block without errors (), and two or more errors occur with probability about ; for such short blocks, correcting one error per block is enough. For , a block without errors has probability only . The largest probability is , at the expected number of errors , and the probabilities become very small beyond .

    Two bar charts. Left, n equals 7: a tall bar of height about 0.93 at zero errors, a small bar of about 0.07 at one error, and nearly invisible bars after that. Right, n equals 1000: a bell-shaped set of bars with its peak, about 0.126, at ten errors, nearly zero at zero errors and becoming very small around twenty errors and beyond.
    Figure 15.2: The probability of exactly errors on (left) and (right). On the right, the dashed line marks the expected number of errors and the dotted line marks .#

    It may seem surprising that is so small for , because each individual error pattern of weight has probability , and this decreases as increases. The explanation is the factor : there is one error pattern with no errors, but patterns with ten errors. Comparing consecutive terms of the binomial distribution shows exactly where the growth of stops outweighing the decrease of .

    Lemma 15.13 (Ratio of consecutive terms)#

    Let . For , This ratio decreases as increases, and it is less than when .

    Proof#

    Writing the binomial coefficients with factorials, and the powers of and contribute the factor . As increases, the numerator decreases and the denominator increases, so the ratio decreases. Finally, the ratio is less than when . Expanding both sides, this inequality reads , which is the same as .

    Consequently when , and when : the probabilities increase up to the point and decrease afterwards. Since , this point lies less than below the mean , so the largest of the probabilities occurs at an within of . Moreover, because the ratio keeps decreasing, the probabilities fall faster and faster as moves beyond the mean. Once reaches twice the mean, each term is less than half of the previous one.

    Proposition 15.14 (Tail beyond twice the mean)#

    Let , and let be an integer with . Then for every , and

    Proof#

    Since , we have , and therefore Multiplying by gives By Lemma 15.13, the ratio is even smaller for , so for every . Adding these inequalities and comparing with the geometric series,

    By Proposition 15.14, the probability of at least errors is at most twice the single probability . To show that this probability is small, we need an upper bound for the binomial coefficient , which involves the factorial . Factorials are estimated by Stirling’s formula, which we use without proof. For our purpose the inequality , valid for every , is enough. Combined with the inequality , it gives the following bound; Problem 15.20 outlines the computation.

    Proposition 15.15 (Exponential bound at twice the mean)#

    Let , and suppose that is an integer smaller than . Then

    The base is less than when ; for it is approximately . For a fixed channel, the bound is therefore a number less than raised to the power , and it decreases exponentially as the block length grows. For , every additional bits of block length increase the expected number of errors by and multiply the bound by about . The table compares the bound with the exact probability.

    bound of Proposition 15.15exact probability of at least errors

    The bound is larger than the exact value because it uses only instead of the full Stirling formula, but both columns decrease rapidly.

    This is the opposite of what happened for triple repetition. There, a code that corrects a fixed number of errors in each short block becomes less reliable as the message gets longer. Here, the number of errors that must be corrected grows with the block: if a code corrects every pattern of up to errors, the probability that a block contains more errors than that becomes smaller as the block length becomes larger. Long blocks are therefore more reliable than short ones, provided the code corrects about twice the expected number of errors.

    15.6 A target for code design#

    Suppose a code of block length has a decoder that returns the transmitted code word whenever at most errors occur, where . This decoder can be wrong only when at least errors occur, and . If is an integer, Proposition 15.15 shows that this happens with probability at most , which tends to as grows. Unlike the triple repetition code, such a family of codes makes long messages reliable. We therefore aim for the following.

    For the channels with a fixed , find codes of block length whose decoders correct every pattern of up to about errors, with rate as large as possible.

    The next note addresses three questions raised by this target. Which code word should the decoder choose for a given received word? Which property of a code guarantees that it corrects every pattern of up to errors? How many code words can such a code have?

    15.7 Exercises#

    Problem 15.16#

    The fivefold repetition code sends as 00000 and as 11111 and decodes by majority vote.

    1. Write the probability that a bit is decoded incorrectly on as a polynomial in .

    2. Evaluate this probability for and , and compare it with uncoded transmission and with triple repetition.

    Problem 15.17#

    Let be the parity-check code of length from Example 15.7.

    1. Prove that the decoder reports failure for the error pattern if and only if is odd.

    2. For and , compute the probability that at least one error occurs and the decoder does not report failure.

    Problem 15.18#

    An ISBN-10 is a string in which are digits from and (the value is written X), chosen so that is a multiple of .

    1. Check that 0-306-40615-2 is a valid ISBN-10.

    2. Prove that changing a single digit always produces an invalid ISBN. You may use that if the prime divides a product , then it divides or .

    3. Prove that exchanging two adjacent unequal digits always produces an invalid ISBN.

    Problem 15.19#

    Suppose is an integer with .

    1. Using Lemma 15.13, prove that , so that the largest probability occurs at two consecutive values of .

    2. Check this by computing for and .

    Problem 15.20#

    Let , and suppose is an integer smaller than .

    1. Using , the inequality , and , prove that .

    2. Prove that satisfies and for , so that for .

    3. Show that for the bound becomes , and combine it with Proposition 15.14 to prove Proposition 15.15.